<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html>
<head>
    <title>资料修改</title>
    <style>
        .error {
            display: block;
            overflow: hidden;
            padding: 0 8px 0 0;
            position: relative;
            color: red;
        }

        #txtFileName {
            width: 300px;
        }

        .btnsubmit {
            border-bottom: #cc4f00 1px solid;
            border-left: #ff9000 1px solid;
            border-top: #ff9000 1px solid;
            border-right: #cc4f00 1px solid;
            text-align: center;
            padding: 2px 10px;
            line-height: 16px;
            background: #e36b0f;
            height: 24px;
            color: #fff;
            font-size: 12px;
            cursor: pointer;
        }
    </style>

</head>

<body>
<div class="container row" id="index-function-section">
    <div class="row">
        <div class="col-md-8">
            <form role="form" id="inputForm" action="${ctx}/profile" method="post" class="form-horizontal middle_box">
                <input type="hidden" name="id" value="${user.id}"/>
                <input type="hidden" name="picPath" id="picPath" value="${user.picPath}"/>

                <fieldset>
                    <legend style="margin:20px -15px;padding-top: 30px;font-weight: 700;font-size: 22px">
                        <small>资料修改</small>
                    </legend>

                    <div class="form-group">
                        <label for="name">用户名：</label>
                        <input type="text" id="name" name="name" value="${user.name}" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail1">邮箱：</label>
                        <input type="email" class="form-control" id="exampleInputEmail1" name="email"
                               value="${user.email}"
                               placeholder="邮箱地址">
                    </div>
                    <div class="form-group">
                        <label for="password">密码：</label>
                        <input type="password" class="form-control" id="plainPassword" name="plainPassword"
                               placeholder="...Leave it blank if no change">
                    </div>
                    <div class="form-group">
                        <label for="password_again">确认密码：</label>
                        <input type="password" class="form-control" id="confirmPassword" name="confirmPassword"
                               placeholder="确认密码" equalTo="#plainPassword"/>
                    </div>

                    <div class="form-actions">
                        <input id="submit_btn" class="" type="submit" value="提交"/>&nbsp;
                        <input id="cancel_btn" class="" type="button" value="返回" onclick="history.back()"/>
                    </div>
                </fieldset>
            </form>
        </div>
        <div class="col-md-4">
            <div class="center">
                <form role="form">
                    <div class="little_box">
                    </div>
                    <div class="uploadPicture padding40left">
                        <img id="imgHead" src="${user.picPath}" width="140" height="180" alt="头像">
                        <input type="file" onchange="uploadHead();" id="basicInfoHead" style="display:none;"
                               name="basicInfoHead"/>
                        <input type="hidden" id="basicHeadUrl">
                        <a href="#basicInfo" id="uploadBasicInfoHead">上传头像</a>
                    </div>
                </form>
            </div>
        </div>
    </div>


    <script>
        $(document).ready(function () {
            //聚焦第一个输入框
            $("#name").focus();
            //为inputForm注册validate函数
            $("#inputForm").validate();
        });
    </script>

    <script src="${ctx}/static/plugins/jquery-validation/1.11.1/jquery.validate.min.js" type="text/javascript"></script>
    <script src="${ctx}/static/plugins/jquery-validation/1.11.1/messages_bs_zh.js" type="text/javascript"></script>
    <script src="${ctx}/static/js/ajaxfileupload.js" type="text/javascript"></script>
    <script>
        //上传头像，触发click方法
        $('#uploadBasicInfoHead').on('click', function () {
            $('#basicInfoHead').click();
        });

        function uploadHead() {
            $.ajaxFileUpload({
                url: "${ctx}/profile/uploadBasicHead",//需要链接到服务器地址
                secureuri: false,
                fileElementId: "basicInfoHead",//文件选择框的id属性
                dataType: 'json',   //json
                success: function (data) {
                    $("#imgHead").attr("src", "${ctx}/" + data.imagePath);
                    $("#picPath").attr("value", "${ctx}/" + data.imagePath);
                    $('#basicHeadUrl').val(data.imagePath);
                }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert('上传失败！');
                }
            });
        }
        ;
    </script>
</div>
</body>
</html>
